package com.ruyuan.commodity.client;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.ruyuan.commodity.domain.DeleteByGoodsWordTypeAndIdRequest;
import com.ruyuan.commodity.api.GoodsWordsClient;
import com.ruyuan.commodity.common.mamager.GoodsWordsManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

/**
 * 商品分词的对外接口
 */
@RestController
public class GoodsWordsClientDefaultImpl implements GoodsWordsClient {

    private static final Logger LOG = LoggerFactory.getLogger(GoodsWordsClientDefaultImpl.class);

    /**
     * 商品分词管理器
     */
    @Autowired
    private GoodsWordsManager goodsWordsManager;

    /**
     * 删除指定分词
     * @param words 分词
     */
    @Override
    public Boolean delete(String words) {
        try {
            goodsWordsManager.delete(words);
            return true;
        } catch (Exception e) {
            LOG.error("delete方法发生异常", e);
            return false;
        }
    }

    /**
     * 添加商品分词
     * @param words 分词
     */
    @Override
    public Boolean addWords(String words) {
        try {
            goodsWordsManager.addWords(words);
            return true;
        } catch (Exception e) {
            LOG.error("addWords方法发生异常", e);
            return false;
        }
    }

    /**
     * 删除商品分词
     * @param request 删除分词的请求对象
     */
    @Override
    public Boolean delete(DeleteByGoodsWordTypeAndIdRequest request) {
        try {
            goodsWordsManager.delete(request.getGoodsWordsType(), request.getId());
            return true;
        } catch (Exception e) {
            LOG.error("delete goodsWordsType 方法发生异常", e);
            return false;
        }
    }

    /**
     * 更新商品分词对应的商品数量
     * @param words 分词
     */
    @Override
    public Boolean updateGoodsNum(String words) {
        try {
            goodsWordsManager.updateGoodsNum(words);
            return true;
        } catch (Exception e) {
            LOG.error("updateGoodsNum方法发生异常", e);
            return false;
        }
    }

    /**
     * 批量更新商品数量
     */
    @Override
    public Boolean batchUpdateGoodsNum() {
        try {
            goodsWordsManager.batchUpdateGoodsNum();
            return true;
        } catch (Exception e) {
            LOG.error("batchUpdateGoodsNum方法发生异常", e);
            return false;
        }
    }

}
